"use strict";

const Service = require("egg").Service;

class GoodsService extends Service {
  // 列表查看
  async goodsList(pageIndex, pageSize, flagqqq) {
    const { app } = this;
    if (flagqqq === -1) {
      const res = await app.mysql.select("list", {
        limit: pageIndex * pageSize, // 返回数据量
        offset: (pageIndex - 1) * pageSize, // 数据偏移量
      });
      return res;
    } else if (flagqqq === true) {
      const res = app.mysql.select("list", {
        where: { statflag: "false" },
        limit: pageIndex * pageSize, // 返回数据量
        offset: (pageIndex - 1) * pageSize, // 数据偏移量
      });
      return res;
    } else {
      const res = app.mysql.select("list", {
        where: { statflag: "true" },
        limit: pageIndex * pageSize, // 返回数据量
        offset: (pageIndex - 1) * pageSize, // 数据偏移量
      });
      return res;
    }
  }
  // add
  async goodsAdd(name) {
    const { app } = this;
    await app.mysql.insert("list", { name: name });
    return true;
  }
  // del
  async goodsDel(id) {
    const { app } = this;
    await app.mysql.delete("list", {
      id: id,
    });
    return true;
  }
  // set
  /* 
    更新的话，需要两个id，修改的参数
  */
  async goodsSet(id, name) {
    const { app } = this;
    await app.mysql.update("list", {
      id: id,
      name: name,
    });
    return true;
  }
}

module.exports = GoodsService;
